﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EnterpriseFund.Common;


namespace EnterpriseFund.Controllers
{
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class YSFPBLManagerController : AdminBaseController
    {
        //
        // GET: /预算分配比例/

        [AuthorityActionFilter("m_DM_YSFPBL", Order = 1)]
        [LogPageActionFilter("预算分配比例管理", Order = 2)]
        public ActionResult Index()
        {
            List<Model.DM_YSFPBL> codeNameList = new List<Model.DM_YSFPBL>();
            ViewData["blcode"] = true;
            BLL.DM_YSFPBL codeNameBll = new BLL.DM_YSFPBL();
            codeNameList = codeNameBll.GetModelList("");
            return View(codeNameList);
        }
        /// <summary>
        /// 编码树相关调用方法 主要用于刷新
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult YSFPBLListPartial()
        {
            BLL.DM_YSFPBL codeNameBll = new BLL.DM_YSFPBL();
            List<Model.DM_YSFPBL> codeNameList = new List<Model.DM_YSFPBL>();
            codeNameList = codeNameBll.GetModelList("");
            ViewData["blcode"] = true;
            return PartialView("YSFPBLListPartial", codeNameList);
        }
        /// <summary>
        /// 编码增加修改
        /// </summary>
        /// <param name="codeNo">编码</param>
        /// <returns>视图</returns>
        public ActionResult DM_YSFPBLEdit(string YSFPBL_DM)
        {
            Model.DM_YSFPBL codeNameObj = new Model.DM_YSFPBL();
            ViewData["blcodeNo"] = true;
            BLL.TaxClass taxClassBLL = new BLL.TaxClass();
            ViewData["TaxClassList"] = taxClassBLL.GetModelList("");
            if (null != YSFPBL_DM)
            {
                YSFPBL_DM = Fetch.estimateString(YSFPBL_DM, CheckGetEnum.Safety);
                BLL.DM_YSFPBL codeNameBll = new BLL.DM_YSFPBL();
                codeNameObj = codeNameBll.GetModel(YSFPBL_DM);
                if (null == codeNameObj)
                {
                    codeNameObj = new Model.DM_YSFPBL();
                }
                else
                {
                    ViewData["blcodeNo"] = false;
                }
            }
            return View(codeNameObj);
        }
        /// <summary>
        /// 删除编码数据
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <returns>是否删除成功</returns>
        public string DelYSFPBL(string YSFPBL_DM)
        {
            string str = string.Empty;
            if (null != YSFPBL_DM)
            {
                YSFPBL_DM = Fetch.estimateString(YSFPBL_DM, CheckGetEnum.Safety);
                BLL.DM_YSFPBL codeNameBll = new BLL.DM_YSFPBL();
                try
                {
                    codeNameBll.Delete(YSFPBL_DM);
                    str = "ok";
                }
                catch (Exception)
                {
                    str = "error";
                }
            }
            return str;
        }
        /// <summary>
        /// 编码保存
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <param name="codeName">编码名字</param>
        /// <returns>是否修改成功</returns>
        public string YSFPBLSave(string YSFPBL_DM, string YSFPBL_MC, string BL1_ZY, string BL2_SS, string BL3_DS, string BL4_XQ, string BL5_XZ, string GS_YSFPBL_MC, string YXBZ, bool isAdd)
        {
            string str = string.Empty;

            YSFPBL_DM = Fetch.estimateString(YSFPBL_DM, CheckGetEnum.Safety);
            YSFPBL_MC = Fetch.estimateString(YSFPBL_MC, CheckGetEnum.Safety);
            BL1_ZY = Fetch.estimateString(BL1_ZY, CheckGetEnum.Safety);
            BL2_SS = Fetch.estimateString(BL2_SS, CheckGetEnum.Safety);
            BL3_DS = Fetch.estimateString(BL3_DS, CheckGetEnum.Safety);
            BL4_XQ = Fetch.estimateString(BL4_XQ, CheckGetEnum.Safety);
            BL5_XZ = Fetch.estimateString(BL5_XZ, CheckGetEnum.Safety);
            GS_YSFPBL_MC = Fetch.estimateString(GS_YSFPBL_MC, CheckGetEnum.Safety);
            YXBZ = Fetch.estimateString(YXBZ, CheckGetEnum.Safety);
            BLL.DM_YSFPBL codeNameBll = new BLL.DM_YSFPBL();
            if (isAdd)//增加时判断编码是否已存在
            {
                if (codeNameBll.Exists(YSFPBL_DM))
                {
                    return "exists";
                }
            }

            Model.DM_YSFPBL codeNameObj = new Model.DM_YSFPBL();
            codeNameObj.YSFPBL_DM = YSFPBL_DM;
            codeNameObj.YSFPBL_MC = YSFPBL_MC;
            codeNameObj.BL1_ZY = Convert.ToDecimal(BL1_ZY);
            codeNameObj.BL2_SS = Convert.ToDecimal(BL2_SS);
            codeNameObj.BL3_DS = Convert.ToDecimal(BL3_DS);
            codeNameObj.BL4_XQ = Convert.ToDecimal(BL4_XQ);
            codeNameObj.BL5_XZ = Convert.ToDecimal(BL5_XZ);
            codeNameObj.GS_YSFPBL_MC = GS_YSFPBL_MC;
            codeNameObj.YXBZ = YXBZ;

            try
            {
                if (isAdd)
                {
                    codeNameBll.Add(codeNameObj);
                }
                else
                {
                    codeNameBll.Update(codeNameObj);
                }
                str = "ok";

            }
            catch (Exception)
            {

                str = "error";
            }

            return str;
        }

    }
}
